package pe.edu.upc.dsd.jms;

import java.util.UUID;

import org.springframework.jms.core.JmsTemplate;

public class RequestResponseClient {
	
	private JmsTemplate jmsTemplate;
	private String requestDestination;
	private String responseDestination;
	
	public String sendAndReceive(final String message){
		final String correlationId= UUID.randomUUID().toString();
		jmsTemplate.convertAndSend(requestDestination, message,
				new CorrelationIdPostProcessor(correlationId));
		return (String) jmsTemplate.receiveSelectedAndConvert(responseDestination,
				"JMSCorrelationID='" + correlationId + "'");
	}
	
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
	public void setRequestDestination(String requestDestination) {
		this.requestDestination = requestDestination;
	}
	public void setResponseDestination(String responseDestination) {
		this.responseDestination = responseDestination;
	}
	
	

}
